package com.atzon.service.impl;

import com.atzon.DAO.UserDAO;
import com.atzon.model.User;
import com.atzon.model.UserFocus;
import com.atzon.model.UserInfo;
import com.atzon.service.UserService;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class UserSrviceImpl implements UserService {
    private UserDAO userDAO = new UserDAO();
    @Override
    public void addLook(Integer uId) {
        UserInfo userInfo = userDAO.getUserInfo(uId);
        if (null != userInfo) {
            Integer look = 0;
            if (null != userInfo.getLook()) {
                look = userInfo.getLook();
            }
            userDAO.updateUserInfo(uId,look + 1);
        }
    }
    @Override
    public void delFocus(Integer id) {
        userDAO.delFocusById(id);
    }
    @Override
    public void repassword(String pass, String email) {
        userDAO.setPass(pass,email);
    }
    @Override
    public void reLogin(Date rtime, Integer user_id) {
        userDAO.reLoginTime(rtime,user_id);
    }
    @Override
    public void updateUserImg(Integer userId, String path) {
        userDAO.updatePic(userId,path);
    }
    @Override
    public void addFocus(Integer userId, Integer focusid) {
        userDAO.addUserFocus(userId,focusid);
    }
    @Override
    public void modMyInfo(Integer userId,String realName, String age, String phone, String sex, String secret, String dept) {
        userDAO.modMyInfo(userId,realName,age,phone,sex,secret,dept);
    }
    @Override
    public long findTotalUserCount(String search) {
        return userDAO.getTotalUser(search);
    }
    @Override
    public long findTotalFocusCount(Integer userId) {
        return userDAO.getTotalFocus(userId);
    }
    @Override
    public User findUserById(String id) throws SQLException {
        return userDAO.findById(id);
    }
    @Override
    public User findUserByName(String name) throws SQLException {
        return userDAO.findByName(name);
    }
    @Override
    public User findUserByEmail(String email) throws SQLException {
        return userDAO.findByEmail(email);
    }
    @Override
    public UserFocus findFocus(Integer userId, Integer focusid) {
        return userDAO.findFocusById(userId,focusid);
    }
    @Override
    public Integer addUser(User user) {
        return userDAO.addUser(user);
    }
    @Override
    public Map<String, Object> getDetail(Integer userId) {
        return userDAO.getDetail(userId);
    }
    @Override
    public Map<String, Object> findUserBaseById(Integer userId) {
        return userDAO.findUserById(userId);
    }
    @Override
    public List<Object[]> findUsers() {
        return userDAO.findAll();
    }
    @Override
    public List<Map<String, Object>> findList(Integer userId,int page,String search) {
        return userDAO.findList(userId,page,search);
    }
    @Override
    public List<Map<String, Object>> getFocus(Integer userId,int page) {
        return userDAO.getFocusUser(userId,page);
    }
}
